package com.jysz.certificate.persistence.dao.system;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.jysz.certificate.persistence.dao.AbstractBaseDao; 
import com.jysz.certificate.persistence.model.system.Treaty;
import com.jysz.certificate.utils.DateUtil;
 
@Repository
public class TreatyDao  extends AbstractBaseDao<Treaty, Long>{
	public void saveTreaty(Treaty treaty){
		this.save(treaty);
	}
	public Treaty shopNameKey(String identifier){
		List<Treaty> list=this.findBy("identifier", identifier);
		if(list!=null&&list.size()>0){
			return list.get(0);
		} 
		return null;
	}
	
	public List<Treaty> treatyList(Long id,String billing){
		Criteria c = this.getSession().createCriteria(Treaty.class);
		c.add(Restrictions.eq("state", true));
		c.createCriteria(Treaty.COLUMN_SHOP).add(Restrictions.eq("id", id));
//		c.createCriteria("financial").add(Restrictions.eq("billing", billing));
		List<Treaty> list=c.list();
		return list;
	}
	
	//xuxiaolong 其他人请不要动
	public List<Treaty> treatyListByBilling(Long id,String billing){
		Criteria c = this.getSession().createCriteria(Treaty.class);
		c.add(Restrictions.eq("state", true));
		c.createCriteria(Treaty.COLUMN_SHOP).add(Restrictions.eq("id", id));
		c.createCriteria("financial").add(Restrictions.eq("billing", billing));
		List<Treaty> list=c.list();
		return list;
	}
	
	public List<Treaty> treatyAppalys(Long id){//查询协议
		Criteria c = this.getSession().createCriteria(Treaty.class);
		c.add(Restrictions.eq("state", true));
		c.createCriteria("financial").add(Restrictions.eq("id", id));
		c.add(Restrictions.ge("endDate", DateUtil.addDays(DateUtil.getSystemDate(),1)));
		List<Treaty> list=c.list();
		return list;
	}
}
